<?php
/**
 * Created by JetBrains PhpStorm.
 * User: oliverson
 * Date: 12/1/12
 * Time: 11:16 PM
 * To change this template use File | Settings | File Templates.
 */
class Program_EMyLink
{
    /*
     * khởi chạy chuong trình
     */
    public function __construct()
    {
        require_once("Config/AutoLoader_EMyLink.php");
        AutoLoader_EMyLink::autoLoader("Session");
        AutoLoader_EMyLink::autoLoader("Request");
        AutoLoader_EMyLink::autoLoader("Router");
        AutoLoader_EMyLink::autoLoader("Secure");
        AutoLoader_EMyLink::autoLoader("DataProvider");
        $session=new Session_EMyLink();
        require_once("Config/Bootstrap_EMyLink.php");
        require_once("Config/EML_EMyLink.php");
        AutoLoader_EMyLink::autoLoader("Lang");
        $lang = Lang_EMyLink::getLang();
        $config=parse_ini_file("/config/config.ini");
        $bootstrap=new Bootstrap_EMyLink($config);
        $EML=new EML_EMyLink($bootstrap->request,$bootstrap->module,$bootstrap->action,$bootstrap->class_action,$bootstrap->application);
        if(file_exists(ROOT_PATH."/application/".$EML->getApplicationName()."/lang/".$lang.".php"))
        {
            require_once(ROOT_PATH."/application/".$EML->getApplicationName()."/lang/".$lang.".php");
            $EML->lang=new $lang;
        }
        $LAYOUT = $this->loadAction($EML);
        $SECURE = new Secure_EMyLink();
        $VIEW=new View_EMyLink($LAYOUT,$EML,$SECURE);
    }
    /*
     * load action
     */
    protected function loadAction($EML)
    {
        $layout="";
        if(file_exists(ROOT_PATH."/application/".$EML->getApplicationName()."/module/".$EML->getModuleName()."/action/".$EML->getActionName().".php") &&
           file_exists(ROOT_PATH."/application/".$EML->getApplicationName()."/module/".$EML->getModuleName()."/template/".$EML->getActionName().".template.php"))
        {
            /*
             * add file layout
             */
            AutoLoader_EMyLink::autoLoader("Layout");
            $layout = new Layout_EMyLink($EML->getApplicationName(),$EML->getModuleName(),$EML->getActionName());
            /*
             * add file action của module tương ứng
             */
            AutoLoader_EMyLink::autoLoader("Action");
            require_once("/application/".$EML->getApplicationName()."/module/".$EML->getModuleName()."/action/".$EML->getActionName().".php");
        }
        return $layout;
    }
}